<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    // 选择排序法去重
    var arr = [1, 2, 2, 1, 1, 1, 1, 3];
    // var l = arr.length;
    for (var i = 0; i < arr.length - 1; i++) {
        for (var j = i + 1; j < arr.length; j++) {
            if (arr[i] === arr[j]) {
                arr.splice(j, 1);
                j--;
            }
        }
    }
    console.log(arr);

    // indexOf()方法去重
    function uniq(arr) {
        var temp = [];
        for (var i = 0; i < arr.length; i++) {
            if (temp.indexOf(arr[i]) == -1) { //查找数组中的第一个数，如果不存在就写入
                temp.push(arr[i]);
            }
        }
        return temp;
    }

</script>

</html>